<?php
class PerformancesController extends AppController {
    var $name = 'Performances';
    var $uses = array('Performance', 'TeacherProfile');
    
    function append($student = null) {
        $this->pageTitle = "添加课堂表现评价";
        $student_id = $student;
        if ($this->Auth->user('role') == 'teacher') {
            if ($this->data) {
                $this->Performance->create();
                $this->Performance->save($this->data);
                $this->Performance->save(array('student_profile_id' => $student_id));
                $current_teacher = $this->TeacherProfile->findByUserId($this->Auth->user('id'));
                $this->Performance->save(array('teacher_profile_id' => $current_teacher['TeacherProfile']['id']));
                $this->Session->setFlash("课堂表现添加成功");
                $this->redirect(array('controller' => 'teacher_profiles', 'action' => 'index'));
            }
        }
        else {
            $this->Session->setFlash("您没有相应的权限");
            $this->redirect(array('controller' => 'users', 'action' => 'login'));
        }
    }
    
    function edit($id = null) {
        $this->pageTitle = "修改课堂表现评价";
        if ($this->Auth->user('role') == 'teacher') {
            if (!$this->data) {
                $this->Performance->id = $id;
                $this->data = $this->Performance;
            }
            else {
                $this->Performance->save($this->data);
                $this->Session->setFlash("修改成功");
            }
        }
        else {
            $this->Session->setFlash("您没有相应的权限");
            $this->redirect(array('controller' => 'users', 'action' => 'login'));
        }
    }
    
    function delete($id = null) {
        if ($this->Auth->user('role') == 'teacher') {
            $this->Performance->delete($id);
            $this->Session->setFlash("成功删除记录");
        }
        else {
            $this->Session->setFlash("您没有相应的权限");
            $this->redirect(array('controller' => 'users', 'action' => 'login'));
        }
    }
    
}
?>